//
//  ModifyPsdViewController.m
//  GoodWayClient
//
//  Created by HuiDong on 15/12/3.
//  Copyright © 2015年 HuiDong. All rights reserved.
//

#import "ModifyPsdViewController.h"
#import "Constant.h"
#import "AFNetworking.h"
#import "AppDelegate.h"

@interface ModifyPsdViewController ()
@property (weak, nonatomic) IBOutlet UITextField *originalPsd;
@property (weak, nonatomic) IBOutlet UITextField *psd;
@property (weak, nonatomic) IBOutlet UITextField *confirmPsd;


//修改密码提交按钮点击事件
- (IBAction)confirmBtn:(UIButton *)sender;
@end

@implementation ModifyPsdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (IBAction)confirmBtn:(UIButton *)sender {
    if ([self.psd.text isEqualToString:self.confirmPsd.text]) {
        //网络请求
        AFHTTPRequestOperationManager *request = [AFHTTPRequestOperationManager manager];
        request.responseSerializer = [AFJSONResponseSerializer serializer];
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
         AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        dic[@"token"] = tempAppDelegate.token;
        dic[@"oldpwd"] = self.originalPsd.text;
        dic[@"newpwd"] = self.psd.text;
        
        [request POST:[NSString stringWithFormat:@"%@%@",url1,@"ChangePwd"] parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSDictionary *dic = (NSDictionary *)responseObject;
            if ([[NSString stringWithFormat:@"%@",dic[@"Status"]] isEqualToString:@"0"]) {
                [[[UIAlertView alloc] initWithTitle:@"提示" message:@"修改成功!" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil] show];
                [self performSelector:@selector(back) withObject:nil afterDelay:1.0f];
            }else
            {
                [[[UIAlertView alloc] initWithTitle:@"提示" message:dic[@"Message"] delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil] show];
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"系统网络申请错误!");
        }];
    }else
    {
        [[[UIAlertView alloc] initWithTitle:@"提示" message:@"两次输入的密码不一致!" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil] show];
    }
}

- (void)back
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
@end
